#include "mainwindowimpl.h"
#include <QFileDialog>
#include <QImage>
#include <QDebug>
#include "brightdlg.h"
#include "processing.h"
#include "gaussdlg.h"
#include "contrastdlg.h"
#include "brightcutdlg.h"
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) 
	: QMainWindow(parent, f), srcimg(new QImage), img(new QImage){
	setupUi(this);
}
MainWindowImpl::~MainWindowImpl(){
	delete srcimg;
	delete img;
}

//

void MainWindowImpl::on_OpenActn_triggered(){
	QString fn = QFileDialog::getOpenFileName(this, trUtf8("Выберите картинку."));
	if(fn.isEmpty())
		return;

	srcimg->load(fn);
	*img = * srcimg;
	imageLbl->setPixmap(QPixmap::fromImage(*srcimg));
}

void MainWindowImpl::on_BrightnessActn_triggered(){
	BrightDlg dlg(this);
	if(dlg.exec() == QDialog::Accepted){
		Processing::Brightness(img, dlg.Bright());
		imageLbl->setPixmap(QPixmap::fromImage(*img));
	}
}

void MainWindowImpl::on_SmoothingAction_triggered(){
	Processing::Smoothing(img);
	imageLbl->setPixmap(QPixmap::fromImage(*img));
}

void MainWindowImpl::on_GaussFilterActn_triggered(){
	GaussDlg dlg(this);
	if(dlg.exec() == QDialog::Accepted){
		Processing::GaussFilter(img, dlg.sigma());
		imageLbl->setPixmap(QPixmap::fromImage(*img));
	}
}

void MainWindowImpl::on_ClearActn_triggered(){
	*img = *srcimg;
	imageLbl->setPixmap(QPixmap::fromImage(*img));
}

void MainWindowImpl::on_InvertingActn_triggered(){
	Processing::Inverting(img);
	imageLbl->setPixmap(QPixmap::fromImage(*img));
}

void MainWindowImpl::on_ContrastActn_triggered(){
	ContrastDlg dlg(this);
	if(dlg.exec() == QDialog::Accepted){
		Processing::contrast(img, dlg.contrast());
		imageLbl->setPixmap(QPixmap::fromImage(*img));
	}
}

void MainWindowImpl::on_BinaryAactn_triggered(){
	Processing::Binary(img);
	imageLbl->setPixmap(QPixmap::fromImage(*img));
}

void MainWindowImpl::on_BrightCutActn_triggered(){
	BrightCutDlg  dlg(this);
	if(dlg.exec() == QDialog::Accepted){
		Processing::BrightCut(img, dlg.lavel());
		imageLbl->setPixmap(QPixmap::fromImage(*img));
	}
}
